package com.ruoyi.fun.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.annotation.DataScope;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.fun.mapper.EcPaymentMapper;
import com.ruoyi.fun.domain.EcPayment;
import com.ruoyi.fun.service.IEcPaymentService;

/**
 * 支付记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-06
 */
@Service
public class EcPaymentServiceImpl implements IEcPaymentService 
{
    @Autowired
    private EcPaymentMapper ecPaymentMapper;

    /**
     * 查询支付记录
     * 
     * @param paymentId 支付记录主键
     * @return 支付记录
     */
    @Override
    @DataScope(userAlias = "p", permission = "fun:payment:query")
    public EcPayment selectEcPaymentByPaymentId(Long paymentId)
    {
        return ecPaymentMapper.selectEcPaymentByPaymentId(paymentId);
    }

    /**
     * 查询支付记录列表
     * 
     * @param ecPayment 支付记录
     * @return 支付记录
     */
    @Override
    @DataScope(userAlias = "p", permission = "fun:payment:list")
    public List<EcPayment> selectEcPaymentList(EcPayment ecPayment)
    {
        System.out.println("[DEBUG] EcPaymentServiceImpl.selectEcPaymentList - 查询参数 orgId: " + ecPayment.getOrgId());
        List<EcPayment> result = ecPaymentMapper.selectEcPaymentList(ecPayment);
        System.out.println("[DEBUG] EcPaymentServiceImpl.selectEcPaymentList - 查询结果数量: " + result.size());
        for (EcPayment payment : result) {
            System.out.println("[DEBUG] EcPaymentServiceImpl.selectEcPaymentList - 支付ID: " + payment.getPaymentId() + ", orgId: " + payment.getOrgId());
        }
        return result;
    }

    /**
     * 新增支付记录
     * 
     * @param ecPayment 支付记录
     * @return 结果
     */
    @Override
    public int insertEcPayment(EcPayment ecPayment)
    {
        ecPayment.setCreateTime(DateUtils.getNowDate());
        ecPayment.setOrgId(SecurityUtils.getDeptId());
        return ecPaymentMapper.insertEcPayment(ecPayment);
    }

    /**
     * 修改支付记录
     * 
     * @param ecPayment 支付记录
     * @return 结果
     */
    @Override
    public int updateEcPayment(EcPayment ecPayment)
    {
        ecPayment.setUpdateTime(DateUtils.getNowDate());
        return ecPaymentMapper.updateEcPayment(ecPayment);
    }

    /**
     * 批量删除支付记录
     * 
     * @param paymentIds 需要删除的支付记录主键
     * @return 结果
     */
    @Override
    public int deleteEcPaymentByPaymentIds(Long[] paymentIds)
    {
        return ecPaymentMapper.deleteEcPaymentByPaymentIds(paymentIds);
    }

    /**
     * 删除支付记录信息
     * 
     * @param paymentId 支付记录主键
     * @return 结果
     */
    @Override
    public int deleteEcPaymentByPaymentId(Long paymentId)
    {
        return ecPaymentMapper.deleteEcPaymentByPaymentId(paymentId);
    }

    /**
     * 根据paymentId和组织ID查询Payment
     * 
     * @param paymentId Payment主键
     * @param orgId 组织ID
     * @return Payment
     */
    @Override
    public EcPayment selectEcPaymentByPaymentIdAndOrgId(Long paymentId, Long orgId)
    {
        return ecPaymentMapper.selectEcPaymentByPaymentIdAndOrgId(paymentId, orgId);
    }

    /**
     * 根据组织ID查询Payment列表
     * 
     * @param ecpayment Payment
     * @param orgId 组织ID
     * @return Payment集合
     */
    @Override
    public List<EcPayment> selectEcPaymentListByOrgId(EcPayment ecpayment, Long orgId)
    {
        return ecPaymentMapper.selectEcPaymentListByOrgId(ecpayment, orgId);
    }
}